﻿@model Squidex.Areas.IdentityServer.Controllers.Setup.SetupVM

@{
    ViewBag.Title = T.Get("setup.title");

    void RenderRuleAsSuccess(string message)
    {
        <div class="row mt-4">
            <div class="col-auto">
                <div class="status-icon status-icon-success mt-2">
                    <i class="icon-checkmark"></i>
                </div>
            </div>

            <div class="col">
                <div>
                    @Html.Raw(message)
                </div>
            </div>
        </div>
    }

    void RenderRuleAsCritical(string message)
    {
        <div class="row mt-4">
            <div class="col-auto">
                <div class="status-icon status-icon-failed mt-2">
                    <i class="icon-exclamation"></i>
                </div>
            </div>

            <div class="col">
                <div>
                    <strong>@T.Get("common.critical")</strong>: @Html.Raw(message)
                </div>
            </div>
        </div>
    }

    void RenderRuleAsWarning(string message)
    {
        <div class="row mt-4">
            <div class="col-auto">
                <div class="status-icon status-icon-warning mt-2">
                    <i class="icon-exclamation"></i>
                </div>
            </div>

            <div class="col">
                <div>
                    <strong>@T.Get("common.warning")</strong>: @Html.Raw(message)
                </div>
            </div>
        </div>
    }
}

<h1>@T.Get("setup.headline")</h1>

<img style="height: 250px" class="mt-2 mb-2" src="squid.svg?title=Welcome&text=Welcome%20to%20the%20Installation%20Process&face=happy" />

<div class="mt-2 mb-2">
    <small class="form-text text-muted">@T.Get("setup.hint")</small>
</div>

<div class="profile-section">
    <h2>@T.Get("setup.rules.headline")</h2>

    @if (Model.IsValidHttps)
    {
        RenderRuleAsSuccess(T.Get("setup.ruleHttps.success"));
    }
    else
    {
        RenderRuleAsCritical(T.Get("setup.ruleHttps.failure"));
    }

    @if (Model.BaseUrlConfigured == Model.BaseUrlCurrent)
    {
        RenderRuleAsSuccess(T.Get("setup.ruleUrl.success"));
    }
    else
    {
        RenderRuleAsCritical(T.Get("setup.ruleUrl.failure", new { actual = Model.BaseUrlCurrent, configured = Model.BaseUrlConfigured }));
    }

    @if (Model.EverybodyCanCreateApps)
    {
        RenderRuleAsWarning(T.Get("setup.ruleAppCreation.warningAdmins"));
    }
    else
    {
        RenderRuleAsWarning(T.Get("setup.ruleAppCreation.warningAll"));
    }

    @if (Model.EverybodyCanCreateTeams)
    {
        RenderRuleAsWarning(T.Get("setup.ruleTeamCreation.warningAdmins"));
    }
    else
    {
        RenderRuleAsWarning(T.Get("setup.ruleTeamCreation.warningAll"));
    }

    @if (Model.IsAssetStoreFtp)
    {
        RenderRuleAsWarning(T.Get("setup.ruleFtp.warning"));
    }

    @if (Model.IsAssetStoreFile)
    {
        RenderRuleAsWarning(T.Get("setup.ruleFolder.warning"));
    }
</div>

<hr />

<div class="profile-section">
    <h2 class="mb-3">@T.Get("setup.createUser.headline")</h2>

    <div>
        @if (Model.HasExternalLogin)
        {
            <div>
                <small class="form-text text-muted mt-2 mb-2">@T.Get("setup.createUser.loginHint")</small>

                <div class="mt-3">
                    <a class="btn btn-primary force-white" asp-controller="Account" asp-action="Login">
                        @T.Get("setup.createUser.loginLink")
                    </a>
                </div>
            </div>
        }

        <div class="profile-separator">
            <div class="profile-separator-text">@T.Get("setup.createUser.separator")</div>
        </div>

        @if (Model.HasPasswordAuth)
        {
            <div>
                <h3>@T.Get("setup.createUser.headlineCreate")</h3>

                @if (!string.IsNullOrWhiteSpace(Model.ErrorMessage))
                {
                    <div class="form-alert form-alert-error">
                        @Model.ErrorMessage
                    </div>
                }

                <form class="profile-form" asp-controller="Setup" asp-action="Setup" method="post">
                    @Html.AntiForgeryToken()

                    <div class="form-group">
                        <label asp-for="Email">@T.Get("common.email")</label>

                        <div error-for="Email"></div>
                        <input asp-for="Email" type="text" class="form-control" />
                    </div>

                    <div class="form-group">
                        <label asp-for="Password">@T.Get("common.password")</label>

                        <div error-for="Password"></div>
                        <input asp-for="Password" type="password" class="form-control" autocomplete="off" />
                    </div>

                    <div class="form-group">
                        <label asp-for="PasswordConfirm">@T.Get("setup.createUser.confirmPassword")</label>

                        <div error-for="PasswordConfirm"></div>
                        <input asp-for="PasswordConfirm" type="password" class="form-control" autocomplete="off" />
                    </div>

                    <div class="form-group mb-0">
                        <button type="submit" class="btn btn-success">@T.Get("setup.createUser.button")</button>
                    </div>
                </form>
            </div>
        }
    </div>

    @if (!Model.HasExternalLogin && !Model.HasPasswordAuth)
    {
        <div>
            @T.Get("setup.createUser.failure")
         </div>
    }
</div>